//
//  CCPresentationCtrl.swift
//  swift_weibo
//
//  Created by ccl on 16/3/5.
//  Copyright © 2016年 LittleBoy. All rights reserved.
//

import UIKit

class CCPresentationCtrl: UIPresentationController {

    var presentedViewFrame = CGRectZero;
    
    override init(presentedViewController: UIViewController, presentingViewController: UIViewController) {
        
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController);
    }
    
    // 容器视图将要重新布局子视图
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews();
        
        converView.frame = containerView!.bounds;
        
        containerView?.insertSubview(converView, atIndex: 0);
       
        presentedView()?.frame = presentedViewFrame;
    }
    
    func converViewDidClick(){
        presentedViewController.dismissViewControllerAnimated(true, completion: nil );
    
    }
    // MARK: 懒加载
    lazy var converView: UIView = {
       
        let view = UIView();
        view.backgroundColor =  UIColor(white: 0.0, alpha: 0.2);
        let tap = UITapGestureRecognizer(target: self, action: "converViewDidClick");
        view.addGestureRecognizer(tap);
        return view;
    }()
}
